<?php
/**
 * 品牌控制器
 */
class BrandController extends IsLoginController{
	
	private $Model;
	//自定执行
	public function __init(){
		parent::__init();
		$this->Model = K('brand');
	}
	
	
	//显示品牌列表
	public function index(){
		$brandInfo = $this->Model->all();
		$this->assign('brandInfo',$brandInfo);
		$this->display();
	}
	
	//异步批量修改列表排序和热门
	public function editSortAndHot(){
		if(IS_AJAX){
			$hotBid = explode(',', $_POST['hotBid']);
			$hotValue = explode(',', $_POST['hotValue']);
			$srotBid = explode(',', $_POST['srotBid']);
			$srotValue = explode(',', $_POST['srotValue']);
			//处理修改热门 排序
			foreach($hotBid as $k => $v){
				$data['brand_hot'] = $hotValue[$k];
				$data['brand_sort'] = $srotValue[$k];
				$this->Model->where("bid = '{$v}'")->update($data);
			}
			

		}
	}
	
	//添加品牌
	public function add(){
		if(IS_POST){
			if(!$this->Model->addBrand()){
				$this->error($this->Molde->error);
			}
			$this->success('添加成功');
		}
		
		$this->display();
	}
	
	
	//修改品牌
	public function edit(){
		if(IS_POST){
			if(!$this->Model->editBrand()){
				$this->error($this->Molde->error);
			}
			$this->success('修改成功');
		}
		//读取信息 赋值页面初始数据
		$bid = Q('get.bid');
		$brandInfo = $this->Model->where("bid ='{$bid}'")->find();
		$this->assign('brandInfo',$brandInfo);
		$this->display();
	}
	
	
	//删除品牌
	public function del(){
		
		if(IS_GET){
			if(!$this->Model->delBrand()){
				$this->error($this->Molde->error);
			}
			$this->success('删除成功');
		}
	}
}
